<template>
  <el-dialog
    :modal="false"
    :modal-append-to-bod="false"
    :visible.sync="dialogVisible"
    width="80%">
    <el-form :inline="true" :model="queryForm" @keyup.enter.native="getDataList()">
      <el-select v-model="queryForm.type" clearable>
        <el-option v-for="type in types" :label="type.label" :value="type.value" :key="type.value"></el-option>
      </el-select>
      <el-form-item>
        <el-input v-model="queryForm.unitName" placeholder="单位/职员名称" clearable/>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryForm.memberName" placeholder="会员姓名" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      :header-cell-style="{background:'#F5F7FA',color:'#606266'}"
      @current-change="handleCurrentChange"
      highlight-current-row
      v-loading="dataListLoading"
      style="width: 100%;">
      <!-- <el-table-column
         prop="id"
         header-align="center"
         align="center"
         label="">
       </el-table-column>-->
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        :formatter="formatType"
        label="上级类型">
      </el-table-column>
      <el-table-column
        prop="superiorName"
        header-align="center"
        align="center"
        label="单位/职员名称">
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="会员姓名">
      </el-table-column>
      <el-table-column
        prop="mobileNum"
        header-align="center"
        align="center"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="birthday"
        header-align="center"
        align="center"
        label="生日">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="注册时间">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click.native="successHandle()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        queryForm: {
          type: '',
          unitName: '',
          memberName: '',
          unitId: ''
        },
        types: [{label: '宾馆职员', value: 1}, {label: '机关单位', value: 0}],
        currentRow: null,
        dialogVisible: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      init () {
        this.dialogVisible = true
        this.queryForm.unitName = ''
        this.queryForm.memberName = ''
        this.queryForm.unitId = ''
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/tra/member/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'unitName': this.queryForm.unitName,
            'memberName': this.queryForm.memberName,
            'type': this.queryForm.type
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 点击确认之后的处理
      successHandle () {
        this.dialogVisible = false
        this.$emit('memberCallback', this.currentRow)
      },
      // 获取选中行数据
      handleCurrentChange (val) {
        this.currentRow = val
      },
      formatType (row, column, cellValue, index) {
        if (row.type === '1') {
          return '宾馆职员'
        } else {
          return '机关单位'
        }
      }
    }
  }
</script>

<style scoped>

</style>
